package co.fitstart.api.web.controller.trading;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import co.fitstart.api.service.OrderService;


/**
 * 
 * @author mohanlan
 *
 */
@Controller
@RequestMapping("")
public class CreditInitController {
    
    private static final Logger logger = LoggerFactory.getLogger(CreditInitController.class);
    
    @Autowired
    private OrderService orderService;
    
    /**
     * 
     * @param name
     * @param pwd
     * @return
     */
    @RequestMapping(value = "/credit-init", method = RequestMethod.GET)
    public @ResponseBody String initCredit(@RequestParam("name") String name, @RequestParam("pwd") String pwd) {
        
        if(StringUtils.equalsIgnoreCase(name, "mohanlan") && StringUtils.equalsIgnoreCase(pwd, "credit-init")) {
            try {
                
                orderService.initCreditData();
                logger.info("#initCredit() - finish init credit data here");
                
            } catch (Exception e) {
                logger.error("initCredit() occurs error:", e);
            }
        }
        
        return "error";
    }
}
